package com.xzmzhp.controller.cosmetic;

import com.github.pagehelper.PageHelper;
import com.xzmzhp.pojo.cosmetic.CosmeticType;
import com.xzmzhp.service.cosmetic.CosmeticTypeService;
import com.xzmzhp.utils.return_tool.ReturnData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 宋雪
 * @Date: 2020/11/15 21:32
 * @Description: 化妆品类型前台交互页面
 */
@Controller
@CrossOrigin
@RequestMapping("/cosmeticType")
public class CosmeticTypeController {
    @Autowired
    private CosmeticTypeService cosmeticTypeService;

    /**
     * 添加化妆品类型
     *
     * @param cosmeticTypeName 化妆品类型名称
     * @return 是否成功
     */
    @RequestMapping("/addCosmeticType")
    @ResponseBody
    public ReturnData addCosmeticType(String cosmeticTypeName) {
        return cosmeticTypeService.addCosmeticType(cosmeticTypeName);
    }

    /**
     * 根据id删除化妆品类型
     *
     * @param cosmeticTypeId 化妆品类型id
     * @return 是否成功
     */
    @RequestMapping("/deleteCosmeticType")
    @ResponseBody
    public ReturnData deleteCosmeticType(Integer cosmeticTypeId) {
        return cosmeticTypeService.deleteCosmeticType(cosmeticTypeId);
    }

    /**
     * 更新化妆品类型
     *
     * @param cosmeticType 化妆品类型信息
     * @return 是否成功
     */
    @RequestMapping("/updateCosmeticType")
    @ResponseBody
    public ReturnData updateCosmeticType(CosmeticType cosmeticType) {
        return cosmeticTypeService.updateCosmeticType(cosmeticType);
    }

    /**
     * 查询所有化妆品类型信息
     *
     * @return 所有化妆品类型信息
     */
    @RequestMapping("/findCosmeticTypeAll")
    @ResponseBody
    public ReturnData selectCosmeticTypeAll(@RequestParam(value = "page", defaultValue = "1") int page,
                                            @RequestParam(value = "limit", defaultValue = "10") int limit) {
        PageHelper.startPage(page, limit);
        return cosmeticTypeService.selectCosmeticTypesAll();
    }

    /**
     * 根据id返回化妆品类型信息
     *
     * @param cosmeticTypeId 化妆品类型id
     * @return 相关化妆品信息
     */
    @RequestMapping("/findCosmeticTypeById")
    @ResponseBody
    public ReturnData selectCosmeticTypeById(Integer cosmeticTypeId) {
        return cosmeticTypeService.selectCosmeticTypeById(cosmeticTypeId);
    }

    /**
     * 根据化妆品名称查询化妆品类型信息
     *
     * @param cosmeticTypeName 化妆品类型名称
     * @return 化妆品信息
     */
    @RequestMapping("/findCosmeticTypeByName")
    @ResponseBody
    public ReturnData selectCosmeticTypeByName(@RequestParam(value = "page", defaultValue = "1") int page,
                                               @RequestParam(value = "limit", defaultValue = "10") int limit,
                                               @RequestParam(value = "cosmeticTypeName") String cosmeticTypeName) {
        PageHelper.startPage(page, limit);
        return cosmeticTypeService.selectCosmeticTypeByName(cosmeticTypeName);
    }
}
